<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>二维码</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" >
    <meta name="generator" content="www.leipi.org" />
    <link rel="stylesheet" href="bootstrap/css/bootstrap.css">
    <!--[if lte IE 6]>
    <link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap-ie6.css">
    <![endif]-->
    <!--[if lte IE 7]>
    <link rel="stylesheet" type="text/css" href="bootstrap/css/ie.css">
    <![endif]-->
    <link rel="stylesheet" href="leipi.style.css">
    <script type="text/javascript" src="../dialogs/internal.js"></script>
    <script type="text/javascript" src="../../../js/jquery/jquery-1.9.1.js"></script>
    <script type="text/javascript" src="../../../js/base/base.js"></script>
    <script type="text/javascript">
        $(function () {
            $('#orgtype').on('change',function(){
                var type =  $('#orgtype').val();
                $('#orgcontent').removeAttr("disabled");
                if(type == 'flowinfo'){
                    $('#orgcontent').val('');
                    $('#orgcontent').attr('placeholder','自动获取流程信息');
                    $('#orgcontent').attr('disabled','disabled');
                }else if(type == 'text'){
                    $('#orgcontent').attr('placeholder','二维码内容')
                }else if(type == 'url'){
                    $('#orgcontent').attr('placeholder','http:// ....')
                }
            });
        })

function createElement(type, name)
{     
    var element = null;     
    try {        
        element = document.createElement('<'+type+' name="'+name+'">');     
    } catch (e) {}   
    if(element==null) {     
        element = document.createElement(type);     
        element.name = name;     
    } 
    return element;     
}
    </script>
</head>
<body>
<div class="content">
    <table class="table table-bordered table-striped table-hover">
     <tr>
        <th><span>控件名称</span><span class="label label-important">*</span></th>
        <th><span>类型</span></th>
    </tr>
    <tr>
        <td>
            <input id="orgname" placeholder="必填项" type="text" />
        </td>
        <td>
            <select id="orgtype"  class="form-control">
                <option value="flowinfo">流程表单信息</option>
                <option value="text">文本</option>
                <option value="url">超链接 url</option>
            </select>
        </td>
    </tr>
    <tr>
        <th><span>文本框样式</span> </th>
        <td>
            宽 <input id="orgwidth" type="text" value="40" class="input-small span1"/> px
            &nbsp;&nbsp;
            高 <input id="orgheight" type="text" value="40" class="input-small span1"/> px
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <label for="orgcontent">内容</label>
            <textarea  class="input-block-level" disabled="disabled" rows="3" id="orgcontent" placeholder="流程表单信息..."></textarea>
        </td>
    </tr>
    </table>
    <div class="alert alert-danger">提示：二维码只支持少量内容，请不要加入大量内容</div>
</div>
<script type="text/javascript">
    $(function () {
    var dataid = $.getQueryString('dataid');

    var dataNumber=parent.pluginId;
        console.log(dataNumber);
    var oNode = null,thePlugins = 'qrcode';
     window.onload = function() {
        if( UE.plugins[thePlugins].editdom ){
            oNode = UE.plugins[thePlugins].editdom;
            var content = oNode.getAttribute('content').replace(/&quot;/g,"\""),gTitle=oNode.getAttribute('title').replace(/&quot;/g,"\""),gWidth=oNode.getAttribute('orgwidth'),gHeight=oNode.getAttribute('orgheight'),gType=oNode.getAttribute('orgtype');
            $G('orgcontent').value = content; //二维码内容
            $G('orgname').value = gTitle;//控件名称
            $G('orgwidth').value = gWidth;//二维码宽度
            $G('orgheight').value = gHeight;//二维码高度
            $G('orgtype').value = gType;//二维码类型
            if(gType != 'flowinfo'){
                    $('#orgcontent').removeAttr("disabled");
            }
        }
    }
    dialog.oncancel = function () {
        if( UE.plugins[thePlugins].editdom ) {
            delete UE.plugins[thePlugins].editdom;
        }
    };
    dialog.onok = function (){
        if( $G('orgname').value == '') {
            alert('控件名称不能为空');
            return false;
        }
    var orgcontent=$G('orgcontent').value.replace(/\"/g,"&quot;"),gTitle=$G('orgname').value.replace(/\"/g,"&quot;"),gFontSize,gWidth=$G('orgwidth').value,gHeight=$G('orgheight').value,gType=$G('orgtype').value;
    
    if( !oNode ) {
        try {
            oNode = createElement('img','leipiNewField');
            oNode.setAttribute('class', "form_item qrcode");
            oNode.setAttribute('data-type', "qrcode");
            oNode.setAttribute('style', "cursor: pointer; margin: 0 auto;");
            oNode.setAttribute('name','DATA_'+dataNumber);
            oNode.setAttribute('id','DATA_'+dataNumber);
            oNode.setAttribute('title',gTitle);
            oNode.setAttribute('content',orgcontent);
            oNode.setAttribute('orgtype',gType);
            oNode.setAttribute('src', '/img/workflow/form/qrcode.png');
            if( gWidth != '' ) {
                oNode.style.width = gWidth + 'px';
                oNode.setAttribute('orgwidth',gWidth );
            }
            if( gHeight != '' ) {
                oNode.style.height = gHeight + 'px';
                oNode.setAttribute('orgheight',gHeight );
            }
            editor.execCommand('insertHtml',oNode.outerHTML);
            return true ;
        } catch ( e ) {
            try {
                editor.execCommand('error');
            } catch ( e ) {
                alert(控件异常);
            }
            return false;
        }
    } else {

        oNode.setAttribute('title',gTitle);
        oNode.setAttribute('content',orgcontent);
        oNode.setAttribute('orgtype',gType);
        if( gWidth != '' ) {
            oNode.style.width = gWidth + 'px';
            oNode.setAttribute('orgwidth',gWidth );
        }
        if( gHeight != '' ) {
            oNode.style.height = gHeight + 'px';
            oNode.setAttribute('orgheight',gHeight );
        }
        delete UE.plugins[thePlugins].editdom;
        return true;
    }
};
    });
</script>
</body>
</html>